﻿using System;
using JetBrains.Annotations;

namespace uMVP
{
    /// <summary>
    /// 指定视图层的预制体路径
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class PrefabPathAttribute : Attribute
    {
        /// <summary>
        /// 预制体路径
        /// </summary>
        public string PrefabPath { get; }

        /// <summary>
        /// 父节点路径
        /// </summary>
        public string ParentPath { get; }

        /// <summary>
        /// View的名字
        /// </summary>
        public string ViewName { get; }

        private static string _prefix = null;

        public PrefabPathAttribute([NotNull] string parentPath) : this(null, parentPath)
        {
        }

        public PrefabPathAttribute([NotNull] string prefabPath, [NotNull] string parentPath)
            : this(null, prefabPath, parentPath)
        {
        }

        public PrefabPathAttribute([NotNull] string viewName, [NotNull] string prefabPath, [NotNull] string parentPath)
        {
            ViewName = viewName;
            PrefabPath = prefabPath;
            if (_prefix == null)
                ParentPath = parentPath;
            else
                ParentPath = _prefix + parentPath;
        }

        // 设置父节点路径的前缀
        public static void SetParentPathPrefix(string prefix)
        {
            _prefix = prefix;
        }
    }
}